//
//  NewsViewController.m
//  phoneTool
//
//  Created by HappyMilk 02 on 2017/7/27.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "NewsViewController.h"
#import "LoginHeader.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"

@interface NewsViewController ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *view_nav;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *lab_title;
@property (weak, nonatomic) IBOutlet UIView *view_categroy;
@property (weak, nonatomic) IBOutlet UILabel *lab_cate_1;
@property (weak, nonatomic) IBOutlet UILabel *lab_cate_2;
@property (weak, nonatomic) IBOutlet UILabel *lab_cate_3;

@property (nonatomic ,strong) UIView *view_cate_bot;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *width_btn_cate;



@end

@implementation NewsViewController
- (IBAction)popvc:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.mainColor = HEXCOLOR(0x77D4C2);
//    self.str_title = LOC_STR(@"Find");
    // Do any additional setup after loading the view.
    
    [self modifyView];
}
- (void)modifyView{
    
    self.width_btn_cate.constant = __kwidth/3;
    
    _view_nav.backgroundColor = _mainColor;
    _lab_title.text = _str_title;
    _lab_title.textColor = [UIColor whiteColor];
    _lab_cate_1.textColor = _mainColor;
    _lab_cate_2.textColor = _mainColor;
    _lab_cate_3.textColor = _mainColor;
    
    _view_cate_bot = [[UIView alloc] initWithFrame:(CGRect){0,_view_categroy.frame.size.height-2,__kwidth/3,2}];
    _view_cate_bot.backgroundColor = _mainColor;
    [self.view_categroy addSubview:_view_cate_bot];
    
    self.scrollView.contentSize = CGSizeMake(__kwidth*3, 0);
    self.scrollView.delegate = self;
    
    VC_INIT_WITH_STORYBOARD(news, OneViewController, vc);
    [self addChildViewController:vc];
    vc.nav_color = _mainColor;
    vc.view.frame = self.scrollView.bounds;
    [self.scrollView addSubview:vc.view];
    
    VC_INIT_WITH_STORYBOARD(news, TwoViewController, vc1);
    vc1.nav_color = _mainColor;
    [self addChildViewController:vc1];
    VC_INIT_WITH_STORYBOARD(news, ThreeViewController, vc2);
    vc2.nav_color = _mainColor;
    [self addChildViewController:vc2];
    
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    CGFloat point_x = scrollView.contentOffset.x;
    NSInteger index = point_x/__kwidth;
    
    self.view_cate_bot.frame = (CGRect){index*__kwidth/3,_view_categroy.frame.size.height-2,__kwidth/3,2};
    
    UIViewController *vc = [self.childViewControllers objectAtIndex:index];
    vc.view.frame = self.scrollView.bounds;
    [self.scrollView addSubview:vc.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
